#include <iostream>
#include <iomanip>
#include "equationsolver.h"
#include <limits>

const double pi = acos(-1);
const double eps = std::numeric_limits<double>::epsilon();
using namespace std;

double func1(double x)
{
        return sin(x/2) - 1;
}

double func2(double x)
{
        return exp(x) - tan(x);
}

double func3(double x)
{
        return x*x*x - 12*x*x + 3*x + 1 ;
}

int main()
{
    typedef double (*fp)(double);
    fp fpi[] = {func1, func2, func3};
    myfunc f1(fpi[0]);
    myfunc f2(fpi[1]);
    myfunc f3(fpi[2]);

    secant S1(0,pi/2,eps,eps,100,f1);
    secant S2(1,1.4,eps,eps,100,f2);
    secant S3(0,-0.5,eps,eps,100,f3);

    cout << "Question D: " << endl;
    cout << "The secant result of f1 is " << setiosflags(ios::fixed) << setprecision(2) << S1.solve() << endl;
    cout << "The secant result of f2 is " << setiosflags(ios::fixed) << setprecision(2) << S2.solve() << endl;
    cout << "The secant result of f3 is " << setiosflags(ios::fixed) << setprecision(2) << S3.solve() << endl;
    cout << "In S1, we change x0=10 x1=13 " << endl;
    secant S1plus(10,13,eps,eps,100,f1);
    cout << "The secant result of f1plus is " << setiosflags(ios::fixed) << setprecision(2) << S1plus.solve() << endl;
    cout << "another root 5*pi" << endl;
    cout << endl;

    return 0;
}